﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Vortex.Drawing {

	/// <summary>
	/// Container of sampler states
	/// </summary>
	struct SamplerState {
		public TextureFilter Filter;
		public TextureAddressMode AddressModeU;
		public TextureAddressMode AddressModeV;
		public ColorU BorderColor;
	}

	/// <summary>
	/// Contains texture options: filtering, address mode, border color
	/// </summary>
	public sealed class TextureOptions {
		private BaseTexture _holder;
		private SamplerState _state;

		/// <summary>
		/// Initializes a new instance of the <see cref="TextureOptions"/> class.
		/// </summary>
		/// <param name="holder">The holder of these options - texture instance.</param>
		internal TextureOptions(BaseTexture holder) {
			_holder = holder;
			_state.Filter = TextureFilter.Linear;
			_state.AddressModeU = TextureAddressMode.Wrap;
			_state.AddressModeV = TextureAddressMode.Wrap;
			_state.BorderColor = ColorU.White;
		}

		/// <summary>
		/// Gets or sets the texture filter.
		/// </summary>
		/// <value>The texture filter.</value>
		public TextureFilter Filter {
			get { return _state.Filter; }
			set {
				if (value != _state.Filter) {
					_holder.Device.Renderer.SetTextureFilter(_holder, value);
					_state.Filter = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the address mode for U axis (X).
		/// </summary>
		/// <value>The address mode for U axis.</value>
		public TextureAddressMode AddressModeU {
			get { return _state.AddressModeU; }
			set {
				if (value != _state.AddressModeU) {
					_holder.Device.Renderer.SetTextureAddressModeU(_holder, value);
					_state.AddressModeU = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the address mode for V axis (Y).
		/// </summary>
		/// <value>The address mode for V axis.</value>
		public TextureAddressMode AddressModeV {
			get { return _state.AddressModeV; }
			set {
				if (value != _state.AddressModeV) {
					_holder.Device.Renderer.SetTextureAddressModeV(_holder, value);
					_state.AddressModeV = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the color of the texture border.
		/// </summary>
		/// <value>The color of the texture border.</value>
		public ColorU BorderColor {
			get { return _state.BorderColor; }
			set {
				if (value != _state.BorderColor) {
					_holder.Device.Renderer.SetTextureBorderColor(_holder, value);
					_state.BorderColor = value;
				}
			}
		}

	}
}
